package com.qqzone.qq.Controller;

import com.qqzone.qq.pojo.Reply;
import com.qqzone.qq.pojo.Topic;
import com.qqzone.qq.pojo.UserBasic;
import com.qqzone.qq.service.ReplyService;

import javax.servlet.http.HttpSession;
import java.time.LocalDateTime;

public class ReplyController {

    private ReplyService replyService;

    public String addReply(Integer topicId, String content, HttpSession session) {

        UserBasic author = (UserBasic) session.getAttribute("userBasic");

        replyService.addReply(new Reply(content, LocalDateTime.now(), author, new Topic(topicId)));

        return "redirect:topic.do?operate=topicDetail&id=" + topicId;
    }

    public String delReply(Integer replyId, Integer topicId) {

        replyService.delReply(replyId);
        return "redirect:topic.do?operate=topicDetail&id=" + topicId;
    }
}
